package game;

import java.util.*;

public class Inventory {

	Vector<Item> v;
	
	public Inventory() {
		v = new Vector<Item>();
	}

	public void addItem(Item currentItem) {
		v.add(currentItem);
	}
	
	public String getWeight() {
		int weight = 0;
		
		Iterator<Item> iterator = v.iterator();
		while (iterator.hasNext()) {
			weight+=iterator.next().weight;
		}
		return Integer.toString(weight);
	}
	
	public String listInv() {
		StringBuilder str = new StringBuilder();
		
		Iterator<Item> iterator = v.iterator();
		str.append("\nInventory:\n");
		while(iterator.hasNext()) {
			Item tmp = iterator.next();
			str.append(tmp.dispName + "\t" + Integer.toString(tmp.weight) + "\n");
//			for (int i = 0; i < tmp.name.length(); i++) {
//				if ('_' == (tmp.name.charAt(i))) {
//					str.append(' ');
//				}  else {
//					str.append(tmp.name.charAt(i));
//				}
//			}
//			str.append("\t" + Integer.toString(tmp.weight) + "\n");
//			//str.append(tmp.name+"\n");
		}
		str.append("Total weight:\t" + getWeight());
		return str.toString();
	}
	
	public boolean hasItem(String itemName) {
		Iterator<Item> iterator = v.iterator();
		while(iterator.hasNext()) {
			Item tmp = iterator.next();
			if (tmp.name.equalsIgnoreCase(itemName)) {
				return true;
			}
		}
		return false;
	}
	
	public boolean removeItem(Item item) {
		boolean removeItem = false;
		if (v.indexOf(item) != -1) {
			v.remove(v.indexOf(item));
			removeItem = true;
		} else {
			removeItem = false;
		}
		return removeItem;
	}
}
